<?php

use console\db\Migration;

/**
 * 推荐位相关表
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m180301_101050_t_position extends Migration {

    /**
     * {@inheritdoc}
     */
    public function up() {

        /**
         * 推荐位表
         * @table `position`
         */
        $this->tableBuilder([
            'name' => 'position',
            'comment' => '推荐位表',
            'columns' => [
                'id' => $this->primaryKey(),
                'name' => $this->string(50)->notNull()->comment('推荐位名称'),
                'label' => $this->char(50)->notNull()->comment('推荐位标识'),
                'page_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('页面ID'),
                'thumb' => $this->char(255)->defaultValue('')->comment('推荐位图示'),
                'width' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('推荐位宽度'),
                'height' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('推荐位高度'),
                'limits' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('推荐内容限制数目'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('推荐位状态：0禁用，10启用'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('删除时间'),
            ]
        ]);

        /**
         * 推荐位内容关系表
         * @table `position_ship`
         */
        $this->tableBuilder([
            'name' => 'position_ship',
            'comment' => '推荐位内容关系表',
            'columns' => [
                'id' => $this->primaryKey(),
                'position_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('推荐位ID'),
                'map_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('地图ID'),
                'model' => $this->char(100)->defaultValue('')->comment('引用数据模型'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('推荐位状态：0禁用，10启用'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('删除时间'),
            ]
        ]);

        /**
         * 推荐位内容表
         * @table `position_data`
         */
        $this->tableBuilder([
            'name' => 'position_data',
            'comment' => '推荐位内容表',
            'columns' => [
                'id' => $this->primaryKey(),
                'position_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('推荐位ID'),
                'title' => $this->string(50)->notNull()->comment('标题'),
                'description' => $this->string(255)->defaultValue('')->comment('简介'),
                'thumb' => $this->char(255)->defaultValue('')->comment('封面'),
                'type' => $this->smallInteger(6)->unsigned()->notNull()->defaultValue(0)->comment('跳转类型'),
                'model' => $this->char(50)->notNull()->comment('模型'),
                'model_id' => $this->char(50)->defaultValue('')->comment('模型参数'),
                'map_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('内部路由ID'),
                'map_data' => $this->string(255)->defaultValue('')->comment('内部路由参数'),
                'url' => $this->char(255)->defaultValue('')->comment('跳转链接'),
                'listorder' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('排序'),
                'admin_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('添加人ID'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态：0禁用，10启用'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
            ]
        ]);

        /**
         * 推荐位页面表
         * @table `position_page`
         */
        $this->tableBuilder([
            'name' => 'position_page',
            'comment' => '推荐位页面表',
            'columns' => [
                'id' => $this->primaryKey(),
                'name' => $this->char(20)->notNull()->comment('标识名称'),
                'title' => $this->string(50)->defaultValue('')->comment('页面名称'),
                'example' => $this->char(255)->defaultValue('')->comment('页面图例'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态：0禁用，10启用'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('删除时间'),
            ]
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function down() {
        $this->dropTable('{{%position_page}}');
        $this->dropTable('{{%position_data}}');
        $this->dropTable('{{%position_ship}}');
        $this->dropTable('{{%position}}');
    }

}
